class LaddersController < ApplicationController
  before_filter :authenticate_user!, except: %w(index show)
  before_filter :admin_required, except: %w(user index show)
  before_action :set_ladder, only: [:show, :edit, :update, :destroy]
  respond_to :html, :json

  def user
    @ladders = Ladder.all
  end

  def index
    @ladders = Ladder.all
  end

  def show
  end

  def new
    @ladder = Ladder.new
  end

  def edit
  end

  def create
    @ladder = Ladder.new(ladder_params)

    respond_to do |format|
      if @ladder.save
        format.html { redirect_to @ladder, notice: 'Ladder was successfully created.' }
        format.json { render action: 'show', status: :created, location: @ladder }
      else
        format.html { render action: 'new' }
        format.json { render json: @ladder.errors, status: :unprocessable_entity }
      end
    end
  end

  def update
    respond_to do |format|
      if @ladder.update(ladder_params)
        format.html { redirect_to @ladder, notice: 'Ladder was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @ladder.errors, status: :unprocessable_entity }
      end
    end
  end

  def destroy
    @ladder.destroy
    respond_to do |format|
      format.html { redirect_to ladders_url }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_ladder
      @ladder = Ladder.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def ladder_params
      params[:ladder]
    end
end
